package com.coin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coin.domain.SysMenu;
import com.coin.mapper.*;
import com.coin.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李力
 * @description 针对表【sys_menu(系统菜单)】的数据库操作Service实现
 * @createDate 2025-05-24 17:08:03
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
        implements SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Autowired
    private SysRoleService roleService;

    /**
     * @Description: 通过用户ID查询用户的菜单数据
     * @Author: 李 力
     * @Date: 2025/5/26
     * @Param: userId
     * @return: List
     */
    @Override
    public List<SysMenu> getMenusByUserId(Long userId) {
        if (userId == null) {
            throw new RuntimeException("用户参数为null");
        }
        boolean result = roleService.checkSuperAdmin(userId);
        if (result) {
            //1.用户为超级管理员则有所有权限
            return this.list();
        }
        //2.不是超级管理员则查询角色，权限
        return sysMenuMapper.getMenusByUserId(userId);
    }
}




